package com.itboye.ihomebank.db;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import java.util.ArrayList;

public class RecordDBManager {
	RecordSQLiteOpenHelper mDbHelper;
	SQLiteDatabase db;

	public RecordDBManager(Context mContext) {
		mDbHelper = new RecordSQLiteOpenHelper(mContext);
	}

	/**
	 * 添加进草稿
	 * 
	 *
	 * @param jsonStr
	 * @return
	 */
	public long addNote( String jsonStr) {
		db = mDbHelper.getWritableDatabase();
		ContentValues cv = new ContentValues();

		cv.put("name", jsonStr);
		long num = db.insert("records", null, cv);
		db.close();
		return num;
	}

	/**
	 * 
	 * 
	 * @return
	 */
	public ArrayList<String> getCaoGaoStr() {
		db = mDbHelper.getReadableDatabase();
		String jsonstr = "";
		ArrayList<String> arrayList=new ArrayList<>();
		Cursor mCursor2 = db.rawQuery(
				"select * from records",null);
		if (mCursor2 != null) {
			while (mCursor2.moveToNext()) {
				jsonstr = mCursor2.getString(mCursor2.getColumnIndexOrThrow("name"));
				arrayList.add(jsonstr);
			}
			mCursor2.close();
		}
		db.close();
		return arrayList;
	}

	public long deleteCaoGao() {
		db = mDbHelper.getWritableDatabase();

		long num = db.delete("records", null, null);
		db.close();
		return num;
	}
}
